package bavaria.hightech.time;



import java.awt.Color;
import java.awt.Graphics;
import java.util.TimerTask;
import java.util.Timer;
import java.util.Calendar;
import java.util.Date;
import java.text.DateFormat;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Clock extends JFrame {
    private JPanel panel;
    private Calendar calendar;
 
    int nn=100, r=90;
    

    private class TickerTask extends TimerTask {
        public void run() {
            panel.repaint();
            
        }
    }

    private class ClockDisplay extends JPanel {
        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);    
            Date date = calendar.getTime();
            DateFormat dateFormatter = DateFormat.getTimeInstance();
            g.setFont(new Font(null,Font.PLAIN,20));
            g.drawString(dateFormatter.format(date), 60, 230);
            dateFormatter = DateFormat.getDateInstance();
            g.drawString(dateFormatter.format(date), 50, 250);
           
            
         // Striche bei 3, 6, 9 und 12 Uhr
            for (int i=0;i<4;i++) {
            
                g.drawLine(
                    nn+(int)((r-7)*Math.cos(Math.toRadians(90*i))),
                    nn+(int)((r-7)*Math.sin(Math.toRadians(90*i))),
                    nn+(int)(r*Math.cos(Math.toRadians(90*i))),
                    nn+(int)(r*Math.sin(Math.toRadians(90*i))));
            }
            // Striche bei jeder Stunde
            for (int i=0;i<12;i++) {
                g.drawLine(
                    nn+(int)((r-5)*Math.cos(Math.toRadians(30*i))),
                    nn+(int)((r-5)*Math.sin(Math.toRadians(30*i))),
                    nn+(int)(r*Math.cos(Math.toRadians(30*i))),
                    nn+(int)(r*Math.sin(Math.toRadians(30*i))));
            }
            // Striche bei jeder Minute (optional)
            for (int i=0;i<60;i++) {
                g.drawLine(
                    nn+(int)((r-2)*Math.cos(Math.toRadians(6*i))),
                    nn+(int)((r-2)*Math.sin(Math.toRadians(6*i))),
                    nn+(int)(r*Math.cos(Math.toRadians(6*i))),
                    nn+(int)(r*Math.sin(Math.toRadians(6*i))));
            }
            
            int hours = date.getHours();
            int minutes = date.getMinutes();
          

            // Stundenzeiger
            g.drawLine(
                nn,nn,nn+(int)(60*Math.cos(Math.toRadians(hours%12*30+minutes/2.0-90))),
                nn+(int)(60*Math.sin(Math.toRadians(hours%12*30+minutes/2.0-90))));

            // Minutenzeiger
            g.setColor(new Color(255,0,0));
            g.drawLine(
                nn,nn,nn+(int)(85*Math.cos(Math.toRadians(minutes*6-90))),
                nn+(int)(85*Math.sin(Math.toRadians(minutes*6-90))));

        }
    }


    public Clock(Calendar calendar) {
    	this.calendar = calendar;
        panel = new ClockDisplay();
        add("Center", panel);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(216, 300);
        setBackground(new Color(170,170,170));
        setVisible(true);

    }
}
